<?php

namespace App\Admin\Actions\ShopOrderReturn;

use App\Library\Logic\OperateLogLogic;
use App\Library\Logic\ShopOrderExtLogic;
use App\Models\ShopOrderReturnModel;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class ShopOrderReturnRejectAction extends RowAction
{
    public $name = '拒绝退款';

    /**
     * handle
     * @param ShopOrderReturnModel $model
     * @param Request $request
     * @return Response
     */
    public function handle(ShopOrderReturnModel $model, Request $request): Response
    {
        $model->or_sell_status = 3;
        $model->or_buy_status = 3;
        $model->or_sell_reject_remark = $request->reason;
        $model->or_approved_time = time();
        $model->edit_user_id = Admin::user()->user_id;
        $model->save();
        ShopOrderExtLogic::updateByWhere(['statusAfterSale' => 3], 'orderId', $model->order_id);
        OperateLogLogic::add(Admin::user()->user_id, 'admin.orderReturn.reject');
        ShopOrderReturnAuction::salesHandle($model, '已拒绝');
        return $this->response()->success('操作成功')->refresh();
    }

    /**
     * handle
     * @return void
     */
    public function form(): void
    {
        $this->text('reason', '拒绝原因')->attribute('maxlength', 255);
    }
}
